package com.kushuigu.controller;

import com.kushuigu.exception.BusinessException;
import com.kushuigu.exception.SystemException;
import com.kushuigu.hp.Code;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException e) {
        System.out.println(e.toString());
        return new Result(null, e.getCode(), "SERVER INTERNAL ERROR");
    }

    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException e) {
        System.out.println(e.toString());
        return new Result(null, e.getCode(), "SERVER INTERNAL ERROR");
    }

    @ExceptionHandler(Exception.class)
    public Result doException(Exception e) {
        System.out.println(e.toString());
        return new Result(null, Code.SERVER_EXCEPTION, "SERVER INTERNAL ERROR");
    }
}
